package com.dhcc.bpm.modules.resource.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dhcc.bpm.modules.resource.service.IOssService;
import com.dhcc.bpm.modules.resource.entity.Oss;
import com.dhcc.bpm.modules.resource.entity.OssVO;
import com.dhcc.bpm.modules.resource.mapper.OssMapper;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @ClassName OssServiceImpl.class
 * @Description  服务实现类
 * @Author xiaFaYu
 * @Date 2020-02-03 14:16
 * @Version V1.0
 * @Copyright:2020东华软件.All rights reserved.
 **/
@Service
public class OssServiceImpl extends BaseServiceImpl<OssMapper, Oss> implements IOssService {

	@Override
	public IPage<OssVO> selectOssPage(IPage<OssVO> page, OssVO oss) {
		return page.setRecords(baseMapper.selectOssPage(page, oss));
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public boolean enable(Long id) {
		// 先禁用
		boolean temp1 = this.update(Wrappers.<Oss>update().lambda().set(Oss::getStatus, 1));
		// 在启用
		boolean temp2 = this.update(Wrappers.<Oss>update().lambda().set(Oss::getStatus, 2).eq(Oss::getId, id));
		return temp1 && temp2;
	}

}
